package LBLD新算法;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

import static MyUtils.MHUtils.*;
import static MyUtils.MHMoban.*;

/*
    每个节点只处理自己（单cur思想）
    做完题一定写入表格
*/
public class 下一个更大气温之间天数739 {

    /*
        比我小的滚
    */
    class Wendu{
        int ind;
        int val;
        Wendu(int x,int y){
            ind=x;
            val=y;
        }
    }
    public int[] dailyTemperatures(int[] t) {
        List<Wendu> list = new ArrayList<>();
        for (int i = 0; i < t.length; i++) {
            Wendu wendu = new Wendu(i, t[i]);
            list.add(wendu);
        }
        Stack<Wendu> s = new Stack<>();
        int[] res = new int[t.length];
        for (int i = t.length-1; i>=0; i--) {
            //初始最右第一个
            if(s.isEmpty()){
                res[i]=0;
                s.push(list.get(i));
            }else{
                Wendu cur=list.get(i);
                //比我小的滚
                while(!s.isEmpty() && cur.val>=s.peek().val)s.pop();
                //出
                if(s.isEmpty()){
                    res[i]=0;
                    s.push(list.get(i));
                }
                else if(cur.val<s.peek().val){
                    res[i]=s.peek().ind-i;
                    s.push(list.get(i));
                }
            }
        }
        return res;
    }
}
